package com.xiaofu.datasource.service.impl;

import com.xiaofu.datasource.annotation.DS;
import com.xiaofu.datasource.constant.DataSourceEmun;
import com.xiaofu.datasource.mapper.UserMapper;
import com.xiaofu.datasource.po.UserPO;
import com.xiaofu.datasource.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author luofuzhou
 * @date 2024/8/23
 * @dec 描述
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @DS(DataSourceEmun.first)
    public List<UserPO> getUserInfo() {
        return userMapper.findAllUser();
    }

    @Override
    @DS(DataSourceEmun.first)
    @Transactional
    public UserPO insertM1(UserPO userPO) {
        int insert = userMapper.insert(userPO);
        System.out.println("insert = " + insert);
        int i = 1/0;
        return userPO;
    }

    @Override
    @DS(DataSourceEmun.second)
    @Transactional
    public UserPO insertM2(UserPO userPO) {
        int insert = userMapper.insert(userPO);
        System.out.println("insert = " + insert);
        int i = 1/0;
        return userPO;
    }
}
